<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" style="width: 400px">
      <h3 style="margin-left: 200px">用户注册</h3>
      <el-form-item label="用户名">
        <el-input v-model="form.YzhvipName" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.YzhvipPassword" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" style="margin-left: 100px"
          >立即注册</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { insertUserInfo } from "../api/user";
export default {
  components: {},
  data() {
    return {
      form: {
        YzhvipName: "",
        YzhvipPassword: "",
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("注册");
      if (this.form.YzhvipName == "") {
        this.$message.error("用户名不能为空");
        return;
      }
      if (this.form.YzhvipPassword == "") {
        this.$message.error("密码不能为空");
        return;
      }
      let insertdata = this.form;
      insertUserInfo(insertdata).then((rsp) => {
        if (rsp.code === 0) {
          this.$message.success("注册成功，返回登录!");
          this.$router.push({ path: "/" });
        } else {
          this.$message.error(rsp.msg);
        }
      });
    },
  },
};
</script>
